package teaching.service;

import org.springframework.stereotype.Service;
import teaching.mapper.CourseMapper;
import teaching.mapper.CourseStudentMapper;
import teaching.pojo.Course;
import teaching.pojo.CourseStudent;
import teaching.pojo.PointRelation;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/3/6
 * Description:
 */
@Service
public class CourseService {
    @Resource
    CourseMapper courseMapper;
    @Resource
    CourseStudentMapper courseStudentMapper;

    public int addCourse(Course newCourse) {
        System.out.println("传到的课程" + newCourse);
        return courseMapper.addCourse(newCourse);
    }

    public int update(Course course) {
        return courseMapper.updateCourse(course);
    }

    public List<Course> list(Long userid) {
        return courseMapper.list(userid);
    }

    public int delete(Long cid) {
//        删除课程影响的表：
        int num = courseMapper.deleteCourse(cid);
        courseStudentMapper.delete(cid);
        courseMapper.resetAutoIncrement();
        return num;
    }

    public List<Course> studentCourse(Long student_id) {
        return courseMapper.listStudentCourse(student_id);
    }

    public void addMulCourseStudent(CourseStudent courseStudent) {
        courseMapper.addMulCourseStudent(courseStudent.getCid(), courseStudent.getStudentIds());
    }
}

